package cn.nju.zyy.action.hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.nju.zyy.model.hello.MessageStore;

import com.opensymphony.xwork2.ActionSupport;

@Component
public class HelloAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private static int helloCount = 0;
	
	private MessageStore messageStore;
	private String userName;
	
	@Override
	public String execute() throws Exception {
		helloCount++;
		if (userName != null) {
			messageStore.setMessage(messageStore.getMessage() + " : " + userName);
		}
		return SUCCESS;
	}

	public int getHelloCount() {
		return helloCount;
	}

	public void setHelloCount(int helloCount) {
		HelloAction.helloCount = helloCount;
	}

	public MessageStore getMessageStore() {
		return messageStore;
	}

	@Autowired
	public void setMessageStore(MessageStore messageStore) {
		this.messageStore = messageStore;
	}

	public String getUserName() {
		return userName;
	}

	/*
	 * The Action class may automatically receive the parameter values
	 * provided it has a public set method that matches the parameter name.
	 * (for both form inputs or query string)
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

}
